package com.klhappy.houyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.bean.GoodsTypeBean;

import java.util.List;

/**
 * Created by Administrator on 2015/11/12.
 */
public class GoodsTypeAdapter extends BaseAdapter {

    private Context context;
    private List<String> list;
    private List<GoodsTypeBean> goodsTypeBeans;
    private int num;

    public GoodsTypeAdapter(Context context, List<GoodsTypeBean> goodsTypeBeans) {
        this.context = context;
        this.goodsTypeBeans = goodsTypeBeans;
    }

    @Override
    public int getCount() {
        if (goodsTypeBeans == null){
            return 0;
        }
        return goodsTypeBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        final ViewHodler hodler;
        if(view == null){
            hodler = new ViewHodler();
            view = LayoutInflater.from(context).inflate(R.layout.item_goods_type , null);
            hodler.goods_tv = (TextView) view.findViewById(R.id.goods_tv);
            view.setTag(hodler);
        }else{
            hodler = (ViewHodler) view.getTag();
        }

        hodler.goods_tv.setText(goodsTypeBeans.get(position).getCa_name());
        hodler.goods_tv.setBackgroundColor(0xFFf7f7f7);
        if (num == position){
            hodler.goods_tv.setBackgroundColor(0xFFFFFFFF);
        }

        return view;
    }

    class ViewHodler{
        public TextView goods_tv;
    }

    public void setNum(int num){
        this.num = num;
    }
}